package com.xuecheng.content.api;

import com.xuecheng.base.resutl.RestResponse;
import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.po.TeachplanMedia;
import com.xuecheng.content.service.ICourseTeacherService;
import com.xuecheng.content.service.ITeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: TeachPlanController
 * @Description: 课程计划编辑接口
 * @Author: Huang Yao
 * @CreateTime: 2024-06-24 20:03
 * @Version: 1.0
 **/
@Api(tags = "课程计划编辑接口")
@RestController
@Slf4j
public class TeachPlanController {

    @Autowired
    private ITeachplanService iTeachplanService;
    @ApiOperation("查询课程计划树形结构")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        return iTeachplanService.findTeachplanTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto teachplan){
        iTeachplanService.saveTeachplan(teachplan);
    }

    @ApiOperation("删除课程计划")
    @DeleteMapping("/teachplan/{teachplanId}")
    public void deleteTeachplan(@PathVariable Long teachplanId){
        iTeachplanService.deleteTeachplanById(teachplanId);
    }

    @ApiOperation("课程计划排序")
    @PostMapping("/teachplan/{moveStatus}/{teachplanId}")
    public void teachplanMove(@PathVariable String moveStatus,@PathVariable Long teachplanId){
        iTeachplanService.teachplanMove(moveStatus,teachplanId);
    }
    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public RestResponse<TeachplanMedia> associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        TeachplanMedia teachplanMedia = iTeachplanService.associationMedia(bindTeachplanMediaDto);
        return RestResponse.success(teachplanMedia);
    }

    @ApiOperation("删除课程计划和媒资信息绑定")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public RestResponse deleteTeachplanMedia(@PathVariable Long teachPlanId,@PathVariable String mediaId){
        log.info("课程id:{},媒资文件id:{}",teachPlanId,mediaId);
        iTeachplanService.deleteTeachplanMedia(teachPlanId,mediaId);
        return RestResponse.success();
    }
}
